package com.wtwd.device.service.impl;


import com.baomidou.mybatisplus.extension.conditions.query.LambdaQueryChainWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.wtwd.device.dao.AppDeviceHeartRateMapper;
import com.wtwd.device.model.entity.DeviceHeartRate;
import com.wtwd.device.model.entity.DeviceHeartRateTotal;
import com.wtwd.device.service.AppDeviceHeartRateService;
import com.wtwd.device.service.AppDeviceHeartRateTotalService;
import com.wtwd.device.util.DateUtils;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 * 服务实现类
 * </p>
 *
 * @author mjy
 * @since 2024-05-16
 */
@Service
public class AppDeviceHeartRateServiceImpl extends ServiceImpl<AppDeviceHeartRateMapper, DeviceHeartRate> implements AppDeviceHeartRateService {


    @Resource
    private AppDeviceHeartRateTotalService deviceHeartRateTotalService;

    @Resource
    private AppDeviceHeartRateMapper appDeviceHeartRateMapper;

    @Override
    public List<DeviceHeartRate> getDayHeartRateByTime(Long deviceId, Long id, String startTime, String endTime) {
        return new LambdaQueryChainWrapper<>(appDeviceHeartRateMapper)
                .eq(DeviceHeartRate::getDeviceId, deviceId)
                .between(DeviceHeartRate::getTime, startTime, endTime)
                .ge(id != null, DeviceHeartRate::getId, id)
                .list();
    }

    @Override
    public DeviceHeartRate getLastDeviceHeartRateByDeviceId(Long deviceId) {
        return appDeviceHeartRateMapper.getLastDeviceHeartRateByDeviceId(deviceId);
    }

    @Override
    public List<DeviceHeartRate> getDayHeartRateByTotalIdGtId(Long totalId, Long id) {
        return new LambdaQueryChainWrapper<DeviceHeartRate>(appDeviceHeartRateMapper)
                .eq(DeviceHeartRate::getDeviceHeartRateTotalId, totalId)
                .gt(id != null, DeviceHeartRate::getId, id)
                .list();
    }

    @Override
    public DeviceHeartRate getLastDeviceHeartRateByTotalId(Long totalId) {
        return appDeviceHeartRateMapper.getLastDeviceHeartRateByTotalId(totalId);
    }
}
